<template>
  <div>

    <el-table :data='tableData' style='width:30%' border>
      <el-table-column label='id' prop='id' />
      <el-table-column label='name' prop='name' />
    </el-table>

    <el-button type='success' @click='add' size='small' style='margin : 6px'>新增</el-button>
    <el-button type='primary' @click='check' size='small' style='margin : 6px'>检查</el-button>
    <el-button type='danger' @click='del' size='small' style='margin : 6px'>删除最后一行</el-button>

  </div>
</template>

<script>
const k = new Date()
export default {
  name: 'test',
  data() {
    return {
      value: undefined,
      tableData: [{ id: 1, name: 'jack' }, { id: 2, name: 'marry' }],
      addState: false,
      defaultTime: [this.$dayjs().format('YYYY-MM-DD 00:00:00'), this.$dayjs().format('YYYY-MM-DD HH:mm:ss')]
    }
  },
  created(){
    let a = 20230224060506
    console.log(this.$dayjs(a.toString()).format('YYYY-MM-DD hh:mm:ss'))
  },
  methods: {
    check() {
      let flag = true
      this.tableData.forEach((item, index) => {
        if (!item.id || !item.name) {
          flag = false
        } else {
          flag = true
        }
      })
      if (flag) {
        this.$message.success('yes')
      } else {
        this.$message.info('no')
      }
    },
    add() {
      this.tableData.push({
        name: undefined,
        id: undefined
      })
      let aa = this.defaultTime[0]
      let bb = new Date(Date.parse(aa))
      console.log(bb)
      console.log(typeof (bb))

    },
    del() {
      let len = this.tableData.length
      if (len === 0) {
        this.$message.error('请先添加数据')
      } else {
        this.tableData.splice(len - 1, 1)
      }

    }
  }
}
</script>

<style scoped>

</style>
